package com.kpijavatraining.module.io;


import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

/**
 * class reads lines from a file
 * @author Bogdan Olexandr
 */
public class FileReader {

	private InputStream stream;
	private DataInputStream data;
	private final String PATH;
	
	public FileReader(String path) throws FileNotFoundException{
		PATH = path;
		stream = new FileInputStream(PATH);
		data = new DataInputStream(stream);
	}
	
	/**
	 * method reads line from a file
	 * @return String
	 * @throws IOException
	 */
	public String read() throws IOException{
		return data.readUTF();
	}
	
	/**
	 * method checks available of lines
	 * @return boolean 
	 * @throws IOException
	 */
	public boolean hasNext() throws IOException{
		return (data.available() > 0);
	}
	
	/**
	 * method closes FileReader
	 * @throws IOException
	 */
	public void close() throws IOException{
		data.close();
	}
}
